{template 'common/header'}
{php echo $this -> set_tabbar($action, 4);}
{if $operation == 'display'}
<div class="main">
    <form action="" method="post" class="form-horizontal form">
        <div class="alert alert-warning">
            注：如商户设置2个充值赠送，1:充值100送10元，2:充值200送20，当用户充值200甚至更多时，只会送20元，不会重复赠送，同类营销活动依此类推。
        </div>
        <div class="panel panel-default">
            <div class="panel-body">
                <a class="btn btn-primary" href="{php echo $this->createWebUrl('recharge', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加充值赠送</a>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="table-responsive panel-body">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width:10%;">显示顺序</th>
                        <th style="width:40%;">活动名称</th>
                        <th style="width:25%;">时间</th>
                        <th style="width:10%;">状态</th>
                        <th style="width:15%;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $recharges $item}
                    <tr>
                        <td><input type="text" class="form-control" name="displayorder[{$item['id']}]" value="{$item['displayorder']}"></td>
                        <td>{$item['title']}</td>
                        <td>
                            生效时间：{php echo date('Y-m-d H:i:s', $item[starttime]);}<br/>
                            过期时间：{php echo date('Y-m-d H:i:s', $item[endtime]);}
                        </td>
                        <td>
                            {if TIMESTAMP<$item['starttime']}
                            <span class="label label-default">未开始</span>
                            {elseif TIMESTAMP>$item['starttime'] && TIMESTAMP<$item['endtime']}
                            {if $item['status'] == 1}
                            <span class="label label-success" >已开启</span>
                            {else}
                            <span class="label label-danger" >已关闭</span>
                            {/if}
                            {else}
                            <span class="label label-default">已结束</span>
                            {/if}
                        </td>
                        <td>
                            {if TIMESTAMP>$item['starttime'] && TIMESTAMP<$item['endtime']}
                            {if $item['status'] == 0}
                            <a class="btn btn-default btn-sm" style="color:green;" href="{php echo $this->createWebUrl('recharge', array('op' => 'check', 'id' => $item['id'], 'status' => $item['status']))}"><i class="fa fa-play"></i></a>
                            {else}
                            <a class="btn btn-default btn-sm" style="color:red;" href="{php echo $this->createWebUrl('recharge', array('op' => 'check', 'id' => $item['id'], 'status' => $item['status']))}"><i class="fa fa-stop"></i></a>
                            {/if}
                            {/if}
                            <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('recharge', array('op' => 'post', 'id' => $item['id']))}"><i class="fa fa-pencil"></i></a>
                            <a class="btn btn-default btn-sm" onclick="return confirm('确认删除吗？');return false;" href="{php echo $this->createWebUrl('recharge', array('op' => 'delete', 'id' => $item['id']))}"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="7">
                            <input name="submit" type="submit" class="btn btn-primary" value="批量排序">
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </form>
    {$pager}
</div>
{else if $operation == 'post'}
<div class="main">
    <form action="" method="post" onsubmit="return check();" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" id="id" name="id" value="{$reply['id']}"/>
        <div class="panel panel-default">
            <div class="panel-heading">
                {$title}
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="title" value="{$reply['title']}" id="title" class="form-control" placeholder="充值赠送"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_daterange('datelimit', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)), true)}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动策略</label>
                    <div class="col-sm-9">
                        <div class="input-group">
                            <span class="input-group-addon" style="border-right:0px;">充值送现金 满</span>
                            <input type="text" class="form-control" name="recharge_value" id="recharge_value" value="{if empty($reply)}0{else}{$reply['recharge_value']}{/if}">
                            <span class="input-group-addon" style="border-left:0px;border-right:0px;">元,送</span>
                            <input type="text" name="give_value" id="give_value" value="{if empty($reply)}0{else}{$reply['give_value']}{/if}" class="form-control" >
                            <span class="input-group-addon" style="border-left:0px;">元</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <button type="submit" class="btn btn-primary col-lg-1" name="submit" value="提交">保存设置</button>
                <input type="hidden" name="token" value="{$_W['token']}"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    function check() {
        if($.trim($('#title').val()) == '') {
            message('没有输入活动标题.', '', 'error');
            return false;
        }
        if($.trim($('#title').val()).length > 30) {
            message('标题不能多于30个字.', '', 'error');
            return false;
        }
        var recharge_value = $.trim($('#recharge_value').val());
        if(recharge_value == '') {
            message('没有输入充值金额.', '', 'error');
            return false;
        }
        if(isNaN(recharge_value)){
            message('充值金额必须为数字.', '', 'error');
            return false;
        }
        var give_value = $.trim($('#give_value').val());
        if(give_value == '') {
            message('没有输入赠送金额.', '', 'error');
            return false;
        }
        if(isNaN(give_value)){
            message('赠送金额必须为数字.', '', 'error');
            return false;
        }
        return true;
    }
</script>
{/if}
{template 'common/footer'}
